<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>stroke描边动画效果</title>
    <style>
      body,
      ul {
        margin: 0;
        padding: 0;
      }

      body {
        background-image: url(../../images/grid.png);
      }
      svg {
        background-color: rgba(255, 0, 0, 0.1);
      }

      #line1 {
        stroke-dasharray: 100px; /* 设置虚线长度 */
        stroke-dashoffset: 0px; /* 设置虚线偏移量 */
        /* 
         animation: 动画名称 动画时长 动画速度曲线 动画延迟时间 动画循环次数 动画方向 动画结束后的状态
        */
        animation: dash 2s linear;
      }

      @keyframes dash {
        from {
          stroke-dashoffset: 100px;
        }

        to {
          stroke-dashoffset: 0px;
        }
      }

      #line2 {
        stroke-dasharray: 100px;
        stroke-dashoffset: 100px;
        /* forwards: 动画结束后保持当前状态 */
        animation: line2Move 2s linear forwards;
      }

      @keyframes line2Move {
        100% {
          stroke-dashoffset: 0;
        }
      }

      #line3 {
        stroke-dasharray: 200px;
        stroke-dashoffset: 200px;
        animation: line3Move 2s linear forwards;
      }

      @keyframes line3Move {
        100% {
          stroke-dashoffset: 0;
        }
      }

      #line1 {
        /* 将线段设置为虚线 */
        stroke-dasharray: 130px;
        /* 偏移 不可见 */
        stroke-dashoffset: 130px;
        animation: line4Move 3s linear forwards;
      }

      @keyframes line4Move {
        100% {
          stroke-dashoffset: 0px; /* 可见 */
        }
      }
    </style>
  </head>
  <body>
    <h3>1. stroke描边动画效果</h3>
    <svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
      <!-- 
        stroke-dasharray: 100, 100, 100, 100
        stroke-dashoffset: 100
      -->
      <line
        id="line1"
        x1="100"
        y1="70"
        x2="100"
        y2="130"
        stroke="red"
        stroke-width="10"
      ></line>
    </svg>

    <h3>2. stroke描边动画效果</h3>
    <svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
      <!-- 
        stroke-dasharray: 100, 100, 100, 100
        stroke-dashoffset: 100
      -->
      <line
        id="line2"
        x1="100"
        y1="70"
        x2="100"
        y2="130"
        stroke="red"
        stroke-width="10"
      ></line>
    </svg>

    <h3>3. stroke描边动画效果</h3>
    <svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
      <!-- 
        stroke-dasharray: 100, 100, 100, 100
        stroke-dashoffset: 100
      -->
      <line
        id="line2"
        x1="100"
        y1="70"
        x2="100"
        y2="130"
        stroke="red"
        stroke-width="10"
      ></line>
    </svg>

    <h3>4. stroke描边动画效果</h3>
    <svg width="300" height="300" xmlns="http://www.w3.org/2000/svg">
      <!-- 
        stroke , 而不是 fill
       -->
      <path
        id="line1"
        d="M 100 70, L 200 70, L 200 100"
        stroke="red"
        stroke-width="10"
        fill="transparent"
      ></path>
    </svg>
  </body>
</html>
